from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_session import Session
from config import *

# 配置数据
db = SQLAlchemy()
redis_store = None


def create_app(config_name):
    """通过传入不同的配置名字，初始化其对应的配置的应用实例"""
    app = Flask(__name__)

    # 配置redis
    global redis_store
    redis_store = redis.StrictRedis(host=config_name.REDIS_HOST, port=config_name.REDIS_PORT, db=0)
    # 配置
    app.config.from_object(config_name)
    # 配置数据库
    db.init_app(app)

    # 设置session保存位置
    Session(app)
    return app